package com.rabiitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    public static final String EXCHANGE_NAME="boot_topic_exchange";
    public static final String QUEUE_NAME="boot_quque";

    /*
    *  参数说明：
    *  id: bean的名称
    *  name：quque名称
    *  auto-declare:自动创建
    *  auto-delete: 自动删除，最后一个消费者和该队列断开连接后，自动删除队列
    *  durable:是否持久化
    *  exclusive:是否独占
    */

    //1.交换机
    @Bean("bootExchange")
    public Exchange bootExchange(){
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build();
    }

    //2.队列
    @Bean("bootQueue")
    public Queue bootQueue(){
        return QueueBuilder.durable(QUEUE_NAME).build();
    }

    //3.队列和交换机的绑定关系
    @Bean
    public Binding binQueueExchange(@Qualifier("bootQueue") Queue queue, @Qualifier("bootExchange") Exchange exchange){
        return  BindingBuilder.bind(queue).to(exchange).with("boot.#").noargs();
    }

}
